package com.hy;

import java.util.HashMap;
import java.util.Map;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * author: Mr.Du
 * Date: 2023/6/16
 * Time: 15:35
 */
public class MinNumberOfSemesters {
    public static void main(String[] args) {
        int[][] relation = {{2,1},{3,1},{1,4}};
        minNumberOfSemesters(1, relation, 1);
    }

    public static int minNumberOfSemesters(int n, int[][] relations, int k) {
        if(relations.length == 0) return n % k == 0? n / k : n / k + 1;
        Map<Integer,Integer> mp = new HashMap<>();
        for(int i = 0;i < relations.length;i++){
            mp.put(relations[i][1], mp.getOrDefault(relations[i][1], 0) + 1);
        }
        int res = 1;
        for(Map.Entry<Integer,Integer> e : mp.entrySet()){
            int tmp = e.getValue();
            if(tmp <= k){
                res += 1;
            }else{
                res += tmp % k == 0? tmp / k : tmp / k + 1;
            }
        }
        return res;
    }
}
